const PENDING = "pending";
const FULLFILLED = "fulfilled";
const REJECTED = "rejected";
export default class Promise {
    #state = PENDING;
    #result = undefined;
    // 将状态更改为失败，成功值为value
    static #resolve = function (value) {
        if (this.#state !== PENDING) return;
        this.#state = FULLFILLED;
        this.#result = value;
    }
    // 将状态更改为成功，失败值为value
    static #reject = function (value) {
        if (this.#state !== PENDING) return;
        this.#state = REJECTED;
        this.#result = value;
    }


    constructor(executor) {
        try {
            // 同步调用执行器函数
            executor(Promise.#resolve.bind(this), Promise.#reject.bind(this));
        } catch (err) {
            Promise.#reject.call(this, err)
        }
    }
};